package com.syni.mdd.sjb.common.component.utils.common.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.Date;

/**
 * @className CustomDateSerializer
 * @description TOO
 * @Author cfx
 * @DATE 2020/5/18 16:17
 * @VERSION 1.0
 **/
public class CustomDateSerializer extends JsonSerializer<Date> {
    @Override
    public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if (date != null) {
            //将localDateTime转换为中国区（+8）时间戳。
            jsonGenerator.writeNumber(String.valueOf(date.getTime()));
        }
    }
}
